package com.cloudsigns.factorymanager2.project.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;

/**
 * Created by tony on 2017/12/12.
 */

public class GeneralPurposePopupWindowAdapter extends BaseAdapter {
    private Context context;
    private String[] datas = {};
    private LayoutInflater inflater;


    public GeneralPurposePopupWindowAdapter(Context context,String[] datas) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);

        if (datas != null)
            this.datas = datas;

    }


    @Override
    public int getCount() {
        return datas.length;
    }

    @Override
    public String getItem(int position) {
        return datas[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_general_purpose_poupwindow_lv, null);
            holder.tv = convertView.findViewById(R.id.tv);


            convertView.setTag(holder);
        } else {
            holder = (GeneralPurposePopupWindowAdapter.ViewHolder) convertView.getTag();
        }

        if (datas != null && datas.length > 0) {
            holder.tv.setText(datas[position]);
        }


        return convertView;
    }

    private class ViewHolder {
        private TextView tv;


    }
}
